class Solution(object):
    def findMedianSortedArrays(self, nums1, nums2):
        """
        :type nums1: List[int]
        :type nums2: List[int]
        :rtype: float
        """
        def getKth(nums1, nums2, k):
            if len(nums1)>len(nums2):
                return getKth(nums2, nums1, k)
            if len(nums1)==0:
                return nums2[k-1]
            if k==1:
                return min(nums1[0], nums2[0])
            i, j = min(len(nums1), k//2), min(len(nums2), k//2)
            if nums1[i-1]>nums2[j-1]:
                return getKth(nums1, nums2[j:], k-j)
            else:
                return getKth(nums1[i:], nums2, k-i)
        length = len(nums1)+len(nums2)
        median1 = getKth(nums1, nums2, (length+1)//2)
        median2 = getKth(nums1, nums2, (length+2)//2)
        return (median1+median2)/2.0

print(Solution().findMedianSortedArrays([1,2], [3,4]))